import { InspectionResult } from "@scmt/api-lis-lis-data";
import { SpecimenEntity } from "@scmt/api-lis-specimen";
import { useRequest } from "@scmt/common-hooks";
import { useApi } from "@scmt/core-api";

export const useInspection = () => {
  const $api = useApi();

  const { data, request, loading } = useRequest({
    getInspection: async (code: string) => {
      return await $api.lis.lisData.getLisDataByBarcode({
        code,
      });
    },
  });

  const getInspection = (specimen: SpecimenEntity) => {
    const { barcode } = specimen;

    return new Promise<InspectionResult[]>((resolve, reject) => {
      request("getInspection", {
        params: barcode,
        onSuccess: resolve,
        onFail: reject,
      });
    });
  };

  return {
    getInspection,
    loading,
  };
};
